-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Program equivalence for Core.Main #2
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6a6cb47
to
2a00051
Compare
fb63d0c
to
a58da50
Compare
1ae6f06
to
05c8fe1
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Defines step-indexed approximation and equivalence relations, sound for contextual approximation and equivalence, respectively. The steps count the nesting of executed function/constructor applications and recursion unfoldings.
Background
First of all, with functions as values represented syntactically (by a closure: expression + environment), the desired equivalence relation on values cannot simply compare them for exact equality. We would like two closures (function values) to be equivalent when they behave in the same way for all admissible arguments, not only when their concrete representations are literally equal.
A correct way to define program equivalence is by contextual equivalence. A context is an expression with exactly one hole. By$C[e]$ we denote the expression obtained by substituting the hole in the context $C$ with the expression $e$ . An expression $e_1$ contextually approximates an expression $e_2$ , denoted $e_1 \lesssim^c e_2$ , if for every context $C$ and environment $E$ such that $E \vdash C[e_1] \downarrow$ (i.e. $C[e_1]$ evaluates to a value in environment $E$ ), we have $E \vdash C[e_2] \downarrow$ . Intuitively, $e_1 \lesssim^c e_2$ means that $e_1$ may always be replaced by $e_2$ preserving the evaluation result (program meaning). Two expressions $e_1, e_2$ are contextually equivalent if $e_1 \lesssim^c e_2$ and $e_2 \lesssim^c e_1$ .
Contextual equivalence essentially states that the programs (expressions) cannot be distinguished by any other program (context). This is the desired notion of program equivalence, but it is hard to work with because the definition requires reasoning about arbitrary contexts.
To prove equivalence of concrete expressions, we would like to have a more "structural" version of program equivalence, defined along the following lines. An expression$e_1$ is an approximation of $e_2$ , denoted $e_1 \lesssim e_2$ , if for every environment $E$ and value $v_1$ such that $E \vdash e_1 \mapsto v_1$ (i.e. $e_1$ evaluates to $v_1$ in environment $E$ ), there exists a value $v_2$ such that $E \vdash e_2 \mapsto v_2$ and $v_1 \lesssim_v v_2$ (value approximation). A value $v_1$ approximates value $v_2$ , denoted $v_1 \lesssim_v v_2$ , if:
With such a definition, proving program equivalence for concrete expressions is more manageable.
However, the "definition" as stated above is not well-founded:$\lesssim_v$ occurs negatively in $a_1 \lesssim_v a_2$ . We cannot replace $a_1 \lesssim_v a_2$ by $a_1 = a_2$ , because then we would not be able to prove that our approximation implies contextual approximation. A solution is to index $\lesssim_v$ by an appropriately defined number of execution steps: $v_1 \lesssim_v^k v_2$ means that $v_1$ approximates $v_2$ in no more than $k$ program execution steps. We ensure the step index $k$ decreases when referring to $\lesssim_v^k$ recursively in its definition.
The general technique of step-indexing is well-established [1, 2], but it needs to be adapted to the particular case of JuvixCore and its evaluation semantics. This adaptation is not straightforward.
Checklist
recur
. Replace global identifiers withrecur
.References